package com.financing.wap.web.controller.api;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.wap.common.ResultMap;
import com.financing.wap.common.ResultMap.STATUS;
import com.financing.wap.common.SessionUtil;
import com.financing.wap.dto.MessageJpushUserPhoneAliasDTO;
import com.financing.wap.service.IMessageJpushUserPhoneAliasService;
import com.financing.wap.util.StringUtil;
import com.financing.wap.web.controller.BaseController;

/**
 * 用户极光推送手机别名管理
 * @author qiye
 *
 */
@Controller("messageJpushUserPhoneAliasController")
@RequestMapping("/api/jpush")
public class MessageJpushUserPhoneAliasController extends BaseController {
	Logger logger = Logger.getLogger(getClass());

	@Autowired
	private IMessageJpushUserPhoneAliasService messageJpushUserPhoneAliasService;
	
	@RequestMapping("/changeMessageJpushUserPhoneAlias")
	@ResponseBody
	public ResultMap changeMessageJpushUserPhoneAlias(String alias,String shopAlias,HttpServletRequest request, HttpServletResponse response){
		ResultMap result = new ResultMap();
		if (StringUtil.isNullOrEmptyStr(alias) && StringUtil.isNullOrEmptyStr(shopAlias)) {  
			result.setStatus(STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
			return result;  
		}
		try {
			MessageJpushUserPhoneAliasDTO dto = new MessageJpushUserPhoneAliasDTO();
			if(!StringUtil.isNullOrEmptyStr(alias)){
				dto.setFpJpushAlias(alias);
			}
			if(!StringUtil.isNullOrEmptyStr(shopAlias)){
				dto.setFpJpushAliasShop(shopAlias);
			}
			dto.setFpUserId(SessionUtil.getSession().getUser().getId());
			messageJpushUserPhoneAliasService.addMessageJpushUserPhoneAlias(dto);
			result.setStatus(STATUS.SUCCESS);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
		}catch(Exception e) {
			e.printStackTrace();
		     logger.error("change message jpush user phone alias error!", e);
			result.setStatus(STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		return result;
	}


	
}
